<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
      http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">

    <changeSet id="001" author="alexander (bigtows) chapchuk">
        <createTable tableName="work_schedule">
            <column name="id" type="uuid">
                <constraints primaryKey="true"/>
            </column>
            <column name="date" type="date">
                <constraints nullable="false"/>
            </column>
            <column name="week_number" type="int">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <createTable tableName="doctor_schedule">
            <column name="id" type="uuid">
                <constraints primaryKey="true"/>
            </column>
            <column name="doctor_id" type="uuid">
                <constraints nullable="false"/>
            </column>
            <column name="work_schedule_id" type="uuid">
                <constraints
                        nullable="false" referencedTableName="work_schedule" referencedColumnNames="id"
                        foreignKeyName="work_schedule_id_fk"/>
            </column>
            <column name="force_schedule" type="boolean">
                <constraints nullable="false"/>
            </column>
            <column name="manual_extra_hours" type="double">
                <constraints nullable="false"/>
            </column>
            <column name="is_actual" type="boolean">
                <constraints nullable="false"/>
            </column>
        </createTable>
        <addUniqueConstraint tableName="doctor_schedule" columnNames="doctor_id,work_schedule_id"/>
        <createTable tableName="doctor_work">
            <column name="id" type="uuid">
                <constraints primaryKey="true"/>
            </column>
            <column name="doctor_schedule_id" type="uuid">
                <constraints
                        nullable="false"
                        referencedTableName="doctor_schedule" referencedColumnNames="id"
                        foreignKeyName="doctor_schedule_id"/>
            </column>
            <column name="modality" type="varchar(30)"/>
            <column name="type_modality" type="varchar(30)"/>
            <column name="used_hours" type="double"/>
            <column name="used_extra_hours" type="double"/>
        </createTable>
    </changeSet>
    <changeSet id="002" author="alexander (bigtows) chapchuk">
        <addColumn tableName="work_schedule">
            <column name="is_actual" type="boolean">
                <constraints nullable="false"/>
            </column>
        </addColumn>
        <dropColumn tableName="doctor_schedule" columnName="is_actual"/>
    </changeSet>
    <changeSet id="003" author="alexander (bigtows) chapchuk">
        <createIndex tableName="doctor_schedule" indexName="work_schedule_id_index">
            <column name="work_schedule_id"/>
        </createIndex>
        <createIndex tableName="doctor_work" indexName="doctor_schedule_id_index">
            <column name="doctor_schedule_id"/>
        </createIndex>
    </changeSet>
    <changeSet id="004" author="alexander (bigtows) chapchuk">
        <addUniqueConstraint tableName="work_schedule" columnNames="date"/>
    </changeSet>
</databaseChangeLog>
